//
//  SHStatus.swift
//  SHWeibo01
//
//  Created by 卫平玉 on 16/7/23.
//  Copyright © 2016年 卫平玉. All rights reserved.
//

import UIKit

class SHStatus: NSObject {

    /*// 如果在此使用 Int的话，在iPhone 5（32位系统）的手机上面，会将Int当成 Int32 来使用
    // 而 Int32位的最大值是没有微博id大的，所以会造成溢出
    var id: Int64 = 0
    /// 当前微博的内容
    var text: String?
    /// 微博的创建时间
    var created_at: String?
    /// 来源
    var source: String?
    /// 当前微博的用户信息
    var user: SHUser?
    /// 当前微博转发微博，因为其内部字段与 HMStatus 一样，所以就设置其类型为 HMStatu
    var retweeted_status: SHStatus?*/
    // MARK: - 模型属性
    /// 创建时间
    var created_at: String?
    /// 微博ID
    var id: Int64 = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    //  用户数据
    var user: SHUser?
    //  转发微博
    var retweeted_status:SHStatus?
    
    var pic_urls: [SHPictureInfo]?
    
    // 转发数
    var reposts_count: Int = 0
    // 评论数
    var comments_count: Int = 0
    // 表态数
    var attitudes_count: Int = 0
    
    init(dict:[String: AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)

    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            
            guard let u = value as? [String: AnyObject] else{
                
                return
            }
            
            user = SHUser(dict: u)
        }else if key == "retweeted_status"{
            
            guard let ret = value as? [String: AnyObject] else{
                
                return
            }
            retweeted_status = SHStatus(dict: ret)
        }else if key == "pic_urls"{
            
            guard let pic = value as? [[String: AnyObject]] else{
                
                return
            }
            
            var tempArr: [SHPictureInfo] = [SHPictureInfo]()
            
            for dict in pic {
                
                let pic = SHPictureInfo(dict: dict)
                
                tempArr.append(pic)
            }
            
            pic_urls = tempArr
                
            
        }else{
            
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
}
